<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <script>

        var arr = [11,4,2,1,1,2,4,3,1,5] ;

        // var arr = [1,1,1,2,2,3,4,4,5,11] ;

        // 排序好了数组   相同的值都在一起
        arr.sort(function(a , b) {
            return a - b ;
        })

        console.log(arr) ;

        for(var i = 0 ; i < arr.length ; i += count) {
            var count = 0 ; 
            for(var j = i ; j < arr.length ; j++) {
                // 相同就统计，不相同就提前结束循环
                if(arr[i] === arr[j]) {
                    
                    count++ ;
                }
                else {
                    break ;
                }
            }
            console.log(arr[i] + '出现了' + count + '次') ;
        }


        // i = 0  3 
        // i = 3  2   break  count = 0
         // i = 3  2   break  count = 0
          // i = 3  2   break  count = 0
           // i = 3  2   break  count = 0

    </script>
    
</body>
</html>